package com.hp.service;

import com.hp.dao.FormMapper;
import com.hp.dao.SeehouseapplicationMapper;
import com.hp.pojo.AgentApply;
import com.hp.pojo.Form;
import com.hp.pojo.Seehouseapplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.transform.Result;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SeeHouseService {

    @Autowired
    SeehouseapplicationMapper seehouseapplicationMapper;


    public Map<String, Object> getAllHouseInfos() {
        HashMap<String,Object> map=new HashMap<>();
        map.put("SeeHouseInfos",seehouseapplicationMapper.GetSeeHouseApplications());
        return map;
    }

    public Map<String, Object>  AddSeeHouseApplication(Seehouseapplication seehouseapplication){
        Map<String,Object> map = new HashMap<>();

        try{
            seehouseapplicationMapper.AddSeeHouseApplication(seehouseapplication);
            map.put("message","添加成功");
            return map;
        }catch (Exception e)
        {
            map.put("message","添加失败");
            e.printStackTrace();
            return map;
        }
    }

    public Map<String, Object>  AcceptSeeHouse (int seehouseapplicationId){
        seehouseapplicationMapper.AcceptSeeHouse(seehouseapplicationId);
        Map<String,Object> map = new HashMap<>();
        map.put("message","success");
        return map;
    }

    public Map<String, Object> QuitSeeHouse (int seehouseapplicationId){
        seehouseapplicationMapper.QuitSeeHouse(seehouseapplicationId);
        Map<String,Object> map = new HashMap<>();
        map.put("message","success");
        return map;
    }

    public Map<String, Object> CompleteSeeHouse(int seehouseapplicationId) {
        seehouseapplicationMapper.CompleteSeeHouse(seehouseapplicationId);
        Map<String, Object> map = new HashMap<>();
        map.put("message", "success");
        return map;
    }

    public Map<String, Object> getSeeHouseByagentid (int agentId) {
        Map<String, Object> allseehouse = new HashMap<>();
        List<Seehouseapplication> pass = new ArrayList<>();
        List<Seehouseapplication> nopass = new ArrayList<>();
        pass.addAll(seehouseapplicationMapper.GetSeehouseApplication2(agentId));
        nopass.addAll(seehouseapplicationMapper.GetSeehouseApplication1(agentId));
        allseehouse.put("pass",pass);
        allseehouse.put("nopass",nopass);
        return allseehouse;
    }

    public Map<String, Object> getSeehouseByuserId (int seehouseapplicationApplyerid){
        Map<String, Object> allseehouse = new HashMap<>();
        allseehouse.put("allseehouse",seehouseapplicationMapper.GetSeehouseByuserId(seehouseapplicationApplyerid));
        return allseehouse;
    }

    public Map<String, Object> getSeehouseByid (int seehouseapplicationId){
        Map<String, Object> seehouse = new HashMap<>();
        seehouse.put("seehouse" , seehouseapplicationMapper.GetSeehouseByid(seehouseapplicationId));
        return seehouse;
    }

    public Map<String, Object> checkApplication(int seehouseapplicationId, int seehouseapplicationState){
        Seehouseapplication seehouseapplication = new Seehouseapplication();
        seehouseapplication.setSeehouseapplicationState(seehouseapplicationState);
        seehouseapplication.setSeehouseapplicationId(seehouseapplicationId);
        seehouseapplicationMapper.CheckApplication(seehouseapplication);

        Map<String,Object> map = new HashMap<>();

        map.put("message", "success");

        return map;
    }
}
